(function($){
 
// Creating the sweetPages jQuery plugin:
$.fn.sweetPages = function(opts){
 
 // If no options were passed, create an empty opts object
 if(!opts) opts = {};
 
 var resultsPerPage = opts.perPage || 3;
 
 // The plugin works best for unordered lists,
 // although OLs would do just as well:
 var ul = this;
 var li = ul.find('li');
 
 li.each(function(){
  // Calculating the height of each li element,
  // and storing it with the data method:
 
  var el = $(this);
  el.data('height',el.outerHeight(true));
 });
 
 // Calculating the total number of pages:
 var pagesNumber = Math.ceil(li.length/resultsPerPage);
 
 // If the pages are less than two, do nothing:
 if(pagesNumber<2) return this;
 
 // Creating the controls div:
 var swControls = $('<div class="swControls">');
 
 for(var i=0;i<pagesNumber;i++)
 {
  // Slice a portion of the li elements, and wrap it in a swPage div:
  li.slice(i*resultsPerPage,(i+1)*resultsPerPage).wrapAll('<div class="swPage" />');
 
  // Adding a link to the swControls div:
  swControls.append('<a href="" class="swShowPage">'+(i+1)+'</a>');
 }
 
 ul.append(swControls);